package mainFragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;

import java.util.ArrayList;

import mainFragment.bean.AdminssionBean;


/**
 * Created by Administrator on 2017/3/10.
 */

public class ZhaoShengSituationMoreAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<AdminssionBean.MajorListBean> arrayList;

    public ZhaoShengSituationMoreAdapter(Context context, ArrayList<AdminssionBean.MajorListBean> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
            myHolder = new MyHolder();
        if(convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.zhaoshengsituation_lv_item, null);
            myHolder.zhaoshengsituation_lv_item_year = (TextView) convertView.findViewById(R.id.zhaoshengsituation_lv_item_year);
            myHolder.zhaoshengsituation_lv_item_major = (TextView) convertView.findViewById(R.id.zhaoshengsituation_lv_item_major);
            myHolder.zhaoshengsituation_lv_item_score = (TextView) convertView.findViewById(R.id.zhaoshengsituation_lv_item_score);
            myHolder.zhaoshengsituation_lv_item_num = (TextView) convertView.findViewById(R.id.zhaoshengsituation_lv_item_num);
            myHolder.zhaoshengsituation_lv_item_rank = (TextView) convertView.findViewById(R.id.zhaoshengsituation_lv_item_rank);
            myHolder.zhaoshengsituation_lv_item_year.setText(arrayList.get(position).getYear());
            myHolder.zhaoshengsituation_lv_item_major.setText(arrayList.get(position).getMajor());
            myHolder.zhaoshengsituation_lv_item_score.setText(arrayList.get(position).getLowest());
            if (!"".equals(arrayList.get(position).getNumber())) {
                myHolder.zhaoshengsituation_lv_item_num.setText(arrayList.get(position).getNumber());
            } else {
                myHolder.zhaoshengsituation_lv_item_num.setText("- -");
            }
            myHolder.zhaoshengsituation_lv_item_rank.setText(arrayList.get(position).getAverage());
            convertView.setTag(myHolder);
        }
        else{
            myHolder = (MyHolder) convertView.getTag();
            myHolder.zhaoshengsituation_lv_item_year.setText(arrayList.get(position).getYear());
            myHolder.zhaoshengsituation_lv_item_major.setText(arrayList.get(position).getMajor());
            myHolder.zhaoshengsituation_lv_item_score.setText(arrayList.get(position).getLowest());
            if (!"".equals(arrayList.get(position).getNumber())) {
                myHolder.zhaoshengsituation_lv_item_num.setText(arrayList.get(position).getNumber());
            } else {
                myHolder.zhaoshengsituation_lv_item_num.setText("- -");
            }
            myHolder.zhaoshengsituation_lv_item_rank.setText(arrayList.get(position).getAverage());
        }
        return convertView;
    }

    class MyHolder{
        TextView zhaoshengsituation_lv_item_year;
        TextView zhaoshengsituation_lv_item_major;
        TextView zhaoshengsituation_lv_item_score;
        TextView zhaoshengsituation_lv_item_num;
        TextView zhaoshengsituation_lv_item_rank;
    }
}
